
package com.zzyl.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;


    @GetMapping("/listAll") // 2.1 查询所有护理级别
    @ApiOperation(value = "查询所有护理级别Level", notes = "查询所有护理级别")
    public ResponseResult<List<NursingLevelVo>>  getAllNursingLevel(){
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.selectAll();
        return ResponseResult.success(nursingLevelVos);
    }

    @PostMapping("/insert")// 2.2.1新增护理级别
    @ApiOperation(value = "新增护理级别Level", notes = "新增护理级别")
    public ResponseResult insertNursingLevel(@ApiParam(value = "护理等级", required = true)
                                             @RequestBody NursingLevelDto nursingLevelDto){

        nursingLevelService.insertNursingLevel(nursingLevelDto);
        return ResponseResult.success();
    }

    @PostMapping("/insertBatch") // 2.2.2 批量插入护理等级信息
    @ApiOperation(value = "批量插入护理等级信息")
    public ResponseResult insertBatch(
            @ApiParam(value = "护理等级数据列表", required = true)
            @RequestBody List<NursingLevelDto> nursingLevelDtos) {
        nursingLevelService.insertBatch(nursingLevelDtos);
        return ResponseResult.success();
    }
    @GetMapping("/listByPage")  //2.3 分页查询护理等级NursingLevel
    @ApiOperation("分页条件查询护理Lelel")
    public ResponseResult selectByPage(
            @ApiParam(value = "护理等级名称") String name,
            @ApiParam(value = "状态")  Integer status,
            @ApiParam(value = "页码", defaultValue = "1", required = true) Integer pageNum,
            @ApiParam(value = "每页数量", defaultValue = "10", required = true) Integer pageSize){
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.selectByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(pageResponse);
    }

  // 2.4 根据id查询护理等级Level
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级Level")
    public ResponseResult<NursingLevelVo> getById(
            @ApiParam(value = "护理等级id", required = true)
            @PathVariable("id") Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.findById(id);
        return ResponseResult.success(nursingLevelVo);
    }

// 2.5更新护理等级信息
    @PutMapping("/update")
    @ApiOperation(value = "更新护理等级信息Level")
    public ResponseResult update(
            @ApiParam(value = "护理等级数据", required = true)
            @RequestBody NursingLevelDto nursingLevelDto) {
            nursingLevelService.update(nursingLevelDto);
        return ResponseResult.success();
    }
// 2.6 删除护理等级信息
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级信息Level")
    public ResponseResult delete(
            @ApiParam(value = "护理等级ID", required = true)
            @PathVariable("id") Long id) {
        nursingLevelService.delete(id);
        return ResponseResult.success();
    }

// 2.7 启用/禁用护理等级
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理等级")
    public ResponseResult enableOrDisable(
            @ApiParam(value = "护理等级ID", required = true) @PathVariable Long id,
            @ApiParam(value = "状态，0：禁用，1：启用", required = true) @PathVariable Integer status) {
        nursingLevelService.enableOrDisable(id, status);
        return ResponseResult.success();
    }

    // 2.8 根据nursingPlan计划id查询护理等级 TODO :路径，前端接口确认
   // @GetMapping
    @ApiOperation("根据nursingPlan计划ids查询护理等级")
    public ResponseResult <List<NursingLevelVo>> listAllByPlanIds(List<Long>ids) {
       List <NursingLevelVo> nursingLevelVos = nursingLevelService.listAllByPlanIds(ids);
       return ResponseResult.success(nursingLevelVos);

    }

}
